package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.VoiceMapper;
import com.tanhua.model.db.Voice;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class VoiceApiImpl implements VoiceApi {

    @Autowired
    private VoiceMapper voiceMapper;

    //上传语音
    @Override
    public void save(Long userId, String url) {
        Voice voice = new Voice();
        voice.setUserId(userId);
        voice.setSoundUrl(url);
        voice.setMark(1); //是否被拾取，1代表没有，2代表被拾取
        voiceMapper.insert(voice);

    }

    //查询所有有效的语音
    @Override
    public List<Voice> findAll() {
        //mark是否被拾取，1代表没有，2代表被拾取
        QueryWrapper<Voice> qw = new QueryWrapper<>();
        qw.eq("mark", 1);
        return voiceMapper.selectList(qw);
    }

    //更新语音状态
    @Override
    public void update(Voice voice) {
        voiceMapper.updateById(voice);
    }
}
